package com.company.thread;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @description: some desc
 * @author: ruoan
 * @date: 2020/12/8 14:37
 */


public class CASDemo2 {
    public static void main(String[] args) {

        AtomicReference<User> atomicReference = new AtomicReference<>();
        User u1 = new User("张三",11);
        User u2 = new User("李四",16);
        atomicReference.set(u1);

        System.out.println(atomicReference.compareAndSet(u1, u2)+": 设置后的值为："+atomicReference.get().toString());

    }
}


class User{
    String name;
    int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}